package com.ruoyi.project.remake.controller;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.remake.domain.PrintClass;
import com.ruoyi.project.remake.service.IPrintClassService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 打印分类与病例分类关联Controller
 *
 * @author 孙山伟
 * @date 2023-03-21
 */
@RestController
@RequestMapping("/remake/printClass")
public class PrintClassController extends BaseController
{
    @Autowired
    private IPrintClassService printClassService;

    /**
     * 查询打印分类与病例分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('remake:printClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrintClass printClass)
    {
        startPage();
        List<PrintClass> list = printClassService.selectPrintClassList(printClass);
        return getDataTable(list);
    }

    /**
     * 导出打印分类与病例分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('remake:printClass:export')")
    @Log(title = "打印分类与病例分类关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrintClass printClass)
    {
        List<PrintClass> list = printClassService.selectPrintClassList(printClass);
        ExcelUtil<PrintClass> util = new ExcelUtil<PrintClass>(PrintClass.class);
        return util.exportExcel(list, "printClass");
    }

    /**
     * 获取打印分类与病例分类关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('remake:printClass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(printClassService.selectPrintClassById(id));
    }

    /**
     * 新增打印分类与病例分类关联
     */
    @PreAuthorize("@ss.hasPermi('remake:printClass:add')")
    @Log(title = "打印分类与病例分类关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrintClass printClass)
    {
        PrintClass check=new PrintClass();
        check.setClassValue(printClass.getClassValue());
        check.setPrintValue(printClass.getPrintValue());
        List<PrintClass> printClasses=printClassService.selectPrintClassList(check);
        if(ObjectUtil.isNotNull(printClasses)&&printClasses.size()!=0){
            return AjaxResult.error("该病例管理与打印分类已经存在，请重新选择");
        }
        return toAjax(printClassService.insertPrintClass(printClass));
    }

    /**
     * 修改打印分类与病例分类关联
     */
    @PreAuthorize("@ss.hasPermi('remake:printClass:edit')")
    @Log(title = "打印分类与病例分类关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrintClass printClass)
    {
        return toAjax(printClassService.updatePrintClass(printClass));
    }

    /**
     * 删除打印分类与病例分类关联
     */
    @PreAuthorize("@ss.hasPermi('remake:printClass:remove')")
    @Log(title = "打印分类与病例分类关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(printClassService.deletePrintClassByIds(ids));
    }
}
